package com.mingserve.raw.runner;

import com.mingserve.common.mqtt.utils.MqttUtils;
import com.mingserve.raw.controller.UploadController;
import com.mingserve.raw.listener.ConfigListener;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 启动MQTT订阅
 *
 * @author lvwshuai
 * @date 2024-01-22
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class MqttRunner implements ApplicationRunner
{
    private final MqttUtils mqttUtils;
    private final UploadController uploadController;
    private final ConfigListener configListener;

    @Override
    public void run(ApplicationArguments args)
    {
        try {
            log.info("Start MQTT subscribe");
            mqttUtils.init();
            configListener.init();
            configListener.subscribe();
            uploadController.subscribe();
        } catch (Exception ex) {
            log.error("Start MQTT subscribe failed：", ex);
        }
    }
}